﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShopShop.Models;
using ShopShop.Models.ViewModels;

namespace ShopShop.Controllers
{
    public class ShoppingCartController : Controller
    {
        BanGiayEntities db = new BanGiayEntities();
        BanGiayRepository bg = new BanGiayRepository();
        //
        // GET: /ShoppingCart/

        public ActionResult Index()
        {
            var cart = ShoppingCart.GetCart(this.HttpContext);

            // Set up our ViewModel
            var viewModel = new ShoppingCartViewModel
            {
                CartItems = cart.GetCart(),
                CartTotal = cart.getTotal()
            };

            // Return the view
            return View(viewModel);
        }

        public ActionResult AddToCart(int id)
        {
            Product pr = db.Products.Single(x=>x.ProductId == id);

            //get current cart
            var cart = ShoppingCart.GetCart(this.HttpContext);

            cart.AddToCart(pr);
            return RedirectToAction("Index");
        }

    }
}
